package com.yh.ldzl.controller;



import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.yh.ldzl.domain.QcDefect;
import com.yh.ldzl.service.QcDefectService;
import com.yh.ldzl.service.QcIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.transform.Result;
import java.util.List;
import java.util.Map;

/**
 * 缺陷管理Controller
 */
@RestController
@RequestMapping("/qc/defect")
public class QcDefectsController extends BaseController {
    @Autowired
    private QcDefectService qcDefectService;


    /**
     * 查询缺陷类型
     * @return
     */

    @PostMapping("/selectQcDefectType")
    @Log(title = "查询缺陷类型", businessType = BusinessType.INSERT)
    public List<Map<String,Object>> selectQcDefectType()
    {

        return qcDefectService.selectQcDefectType();

    }
    //查询缺陷列表
    @PostMapping("/selectQcDefectList")
    @Log(title = "查询缺陷列表", businessType = BusinessType.INSERT)
    public IPage<QcDefect> selectQcDefectList(@RequestBody Map<String, Object> params) {
        String defect_name = (String) params.get("defect_name");
        String index_type = (String) params.get("index_type");
        String defect_level = (String) params.get("defect_level");
        Integer pageNum = (Integer) params.get("pageNum");
        Integer pageSize = (Integer) params.get("pageSize");

        System.out.println("接收参数：" + params);
        return qcDefectService.selectQcDefectList(defect_name, index_type, defect_level,
                pageNum != null ? pageNum : 1,
                pageSize != null ? pageSize : 10);
    }

    //添加缺陷
    @PostMapping("/insertQcDefect")
    @Log(title = "添加缺陷", businessType = BusinessType.INSERT)
    public boolean insertQcDefect(@RequestBody QcDefect qcDefect){
        System.out.println(qcDefect);
        return qcDefectService.insertQcDefect(qcDefect);
    }
    //修改缺陷
    @PostMapping("/updateQcDefect")
    @Log(title = "修改缺陷", businessType = BusinessType.INSERT)
    public boolean updateQcDefect(@RequestBody QcDefect qcDefect){

        System.out.println(qcDefect);
        return qcDefectService.updateQcDefect(qcDefect);
    }

    //删除缺陷
    @PostMapping("/deleteQcDefect")
    @Log(title = "删除缺陷", businessType = BusinessType.INSERT)
    public boolean deleteQcDefect(@RequestBody List<Long> ids){
        System.out.println(ids);
        return qcDefectService.deleteQcDefect(ids);
    }




}
